package com.example.hotelsystem;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.hotelsystem.entity.FloorDetails;
import com.example.hotelsystem.entity.PageConfig;
import com.example.hotelsystem.entity.ServerConfig;
import com.example.hotelsystem.page.Pagesize;
import com.example.hotelsystem.server.Server;
import com.example.hotelsystem.service.PageConfigService;
import com.example.hotelsystem.service.ServerConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class ApplicationRunnerImpl implements ApplicationRunner {
    @Autowired
    private ServerConfigService serverConfigService;
    @Autowired
    private PageConfigService pageConfigService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        QueryWrapper<ServerConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete",0);
        queryWrapper.orderByDesc("create_time");
        List<ServerConfig> list = serverConfigService.list(queryWrapper);
        ServerConfig serverConfig = list.get(0);
        Server.setData(serverConfig.getIp(),serverConfig.getPort());
        System.out.println("============================");
        System.out.println(Server.iphost+Server.port );


        QueryWrapper<PageConfig> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("is_delete",0);
        queryWrapper.orderByDesc("create_time");
        List<PageConfig> list2 = pageConfigService.list(queryWrapper2);
        PageConfig pageConfig = list2.get(0);
        Pagesize.setData(pageConfig.getPageSize1(),pageConfig.getPageSize2(),pageConfig.getPageSize3());
        System.out.println("============================");
        System.out.println(Pagesize.pageSize1);
    }
}